package thread;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.Test;
import thread.PublicClass.PrivateClass;

/**
 * Desc: 线程内置类测试
 * @author: lisha 2018/6/29 14:27
 */
public class Run {

    static Logger logger = LoggerFactory.getLogger(Run.class);


    @Test
    public void test_1(){
        PublicClass pub = new PublicClass();
        pub.setUserName("name");
        pub.setPassword("pwd");
        logger.info(pub.toString());

        PrivateClass pri = pub.new PrivateClass();
        pri.setAge("18");
        pri.setAddress("addredd");
        logger.info(pri.toString());

    }

    /**
     * Desc: 内置类与同步 实验1 测试方法
     * @author: lisha 2018/6/29 15:05
     */

//    @Test
    public void test1(){  //Test方法for循环只执行一次 为毛？
//    public static void main(String[] args) {
        final OutClass.Inner inner = new OutClass.Inner();
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                inner.method1();
            }
        }, "A");

        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                inner.method2();
            }
        }, "B");

        t1.start();
        t2.start();
    }

    /**
     * Desc: 内部类线程 实验2
     * @author: lisha 2018/6/29 15:10
     */
    public static void main(String[] args) {

        final OutClass.Inner inner = new OutClass.Inner();
        final OutClass.InnerClass2 inner2 = new OutClass.InnerClass2();
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                inner.method1();
            }
        }, "T1");

        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                inner.method2();
            }
        }, "T2");

        Thread t3 = new Thread(new Runnable() {
            @Override
            public void run() {
                inner2.method1();
            }
        }, "T3");

        t1.start();
        t2.start();
        t3.start();

    }


}
